package cct.smartmatrix.advertisement.controller;

import cct.smartmatrix.advertisement.domain.User;
import cct.smartmatrix.advertisement.repository.UserRepository;
import cct.smartmatrix.advertisement.service.UserService;
import cct.smartmatrix.advertisement.utils.JWTUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.HashMap;
import java.util.Map;

/**
 * 作者：姜兆京 on 2017/7/3 19:57
 * 邮箱：763834497@qq.com
 */
@RestController
@RefreshScope
@Slf4j
public class UserController {

    @Autowired
    UserService userService;

    //    http://localhost:8084/user/3
    @RequestMapping(value = "/user/{zcUserId}", method = RequestMethod.GET, produces = "application/json")
    public Map<Object, Object> findById(@PathVariable String zcUserId, HttpServletRequest request) {
        String auth = request.getHeader("auth");
        if(StringUtils.isEmpty(auth)) {
            Map<Object, Object> error = new HashMap<>();
            error.put("code", "-1");
            error.put("msg", "no auth, please recheck it.");
            log.error("no auth");
            return error;
        }
        Map<Object, Object> user = userService.initUser(zcUserId);
        return user;
    }


}
